import echarts from '../../static/h5/echarts.min.js'


const colorsArr = ['#7021FF', '#C3A5FF', '#00D3FA', '#3181FF', '#A5D9FF'];
const colorsArrTwo = ['#7021FF', '#A5D9FF', '#00D3FA'];


// 填充大数据分析图表 1和2
function fillChartOneTwo(info) {

	let yearArr = []; // 年份
	let FMGB_ZSArr = []; //
	let FMSQ_YXArr = []; //授权
	let SYXX_YXArr = []; //实用新型
	let RZ_YXArr = []; // 软著有效数
	let WGSJ_YXArr = []; // 外观设计有效数
	let DNKJCXCGKBJSHLArr = []; // 当年科技创新成果可比技术含量


	for (let s of info) {

		FMGB_ZSArr.push(s.fmgbZs)
		FMSQ_YXArr.push(s.fmsqYx)
		SYXX_YXArr.push(s.syxxYx)
		RZ_YXArr.push(s.rzYx)
		WGSJ_YXArr.push(s.wgsjYx)
		DNKJCXCGKBJSHLArr.push(s.dnkjcxcgkbjshl)
		yearArr.push(s.years);

	}

	var dom = document.getElementById("dsj_zscq");
	var myChart = echarts.init(dom);
	var option;

	option = {
		color: colorsArr,
		silent: false, //取消点击高亮
		tooltip: {
			trigger: 'axis',
			axisPointer: {
				// Use axis to trigger tooltip
				type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
			}
		},
		legend: {
			selectedMode: true,
			data: ['类型一', '类型二', '软件著作权', '类型三', '类型四']
		},
		grid: {
			left: '2%',
			right: '2%',
			bottom: '2%',
			containLabel: true
		},
		xAxis: {
			type: 'category',
			data: yearArr,
			axisLabel: {

				fontSize: 10
			},
		},
		yAxis: {
			type: 'value'

		},
		series: [{
				name: '类型一',
				type: 'bar',
				barMaxWidth: 30,
				stack: 'total',
				clickable: false,

				emphasis: {
					focus: 'series'
				},
				data: FMSQ_YXArr
			},
			{
				name: '类型二',
				type: 'bar',
				barMaxWidth: 30,
				stack: 'total',
				clickable: false,

				emphasis: {
					focus: 'series'
				},
				data: FMGB_ZSArr
			},
			{
				name: '软件著作权',
				type: 'bar',
				barMaxWidth: 30,
				stack: 'total',
				clickable: false,

				emphasis: {
					focus: 'series'
				},
				data: RZ_YXArr
			},
			{
				name: '类型三',
				type: 'bar',
				barMaxWidth: 30,
				stack: 'total',
				clickable: false,

				emphasis: {
					focus: 'series'
				},
				data: SYXX_YXArr
			},
			{
				name: '类型四',
				type: 'bar',
				barMaxWidth: 30,
				stack: 'total',
				clickable: false,

				emphasis: {
					focus: 'series'
				},
				data: WGSJ_YXArr
			}


		]
	};
	console.log('有效知识产权成功 ');
	if (option && typeof option === 'object') {
		myChart.setOption(option);
	}

	// 企业历年创新成果趋势
	dom = document.getElementById("dsj_cxcg");
	myChart = echarts.init(dom);
	option = {
		color: colorsArr,
		silent: false, //取消点击高亮
		tooltip: {
			trigger: 'axis',
			axisPointer: {
				type: 'cross',
				crossStyle: {
					color: '#999999'
				}
			}
		},
		legend: {
			selectedMode: true,
		},
		grid: {
			left: '2%',
			right: '2%',
			bottom: '2%',
			containLabel: true
		},
		xAxis: {
			type: 'category',
			data: yearArr,
			axisLabel: {

				fontSize: 10
			},
		},
		yAxis: {
			type: 'value'
		},
		series: [{
				data: DNKJCXCGKBJSHLArr,
				type: 'line',

			}

		]
	};
	if (option && typeof option === 'object') {
		myChart.setOption(option);
	}

}


// 填充大数据分析图表 3 
function fillChartThree(info) {

	let yearArr = []; // 年份
	let CFMWYXZSCQSLArr = []; // 除
	let FMSQ_YXArr = []; //有效授权
	let DNZLHJLArr = []; //当年含金量


	for (let s of info) {

		CFMWYXZSCQSLArr.push(s.cfmwyxzscqsl)
		FMSQ_YXArr.push(s.fmsqYx)
		DNZLHJLArr.push(s.dnzlhjl)
		yearArr.push(s.years);

	}

	//  含金量图
	var dom = document.getElementById("dsj_zlhjl");
	var myChart = echarts.init(dom);

	var option = {
		color: colorsArrTwo,
		silent: false, //取消点击高亮
		tooltip: {
			trigger: 'axis',
			axisPointer: {
				// Use axis to trigger tooltip
				type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
			},
			textStyle: {
				fontSize: 10,

			},
			padding: [8, 8],
			position: [6, 50]


		},
		grid: {
			left: '2%',
			right: '2%',
			bottom: '2%',
			containLabel: true
		},
		legend: {
			// 当年全体知识产权数量(公布+授权)
			data: ['当年全体数量', '当年含金量', '当年全体知识产权数量(公布+授权)']
		},
		xAxis: {
			type: 'category',
			data: yearArr,
			axisLabel: {

				fontSize: 10
			},
		},

		yAxis: [{
				type: 'value',
				name: '',
				min: 0,
				// max: 100,
				axisLabel: {
					formatter: '{value}'
				}
			},
			{
				type: 'value',
				name: '',
				axisLabel: {
					formatter: '{value} %'
				}
			}
		],
		series: [{
				name: '当年全体知识产权数量(公布+授权)',
				type: 'bar',
				barMaxWidth: 30,
				stack: 'total',
				label: {
					show: false
				},
				emphasis: {
					focus: 'series'
				},
				data: CFMWYXZSCQSLArr
			},
			{
				name: '当年全体数量',
				type: 'bar',
				barMaxWidth: 30,
				stack: 'total',
				label: {
					show: false
				},
				emphasis: {
					focus: 'series'
				},
				data: FMSQ_YXArr
			},
			{
				name: '当年含金量',
				type: 'line',
				yAxisIndex: 1,
				label: {
					show: false
				},
				emphasis: {
					focus: 'series'
				},
				data: DNZLHJLArr
			}
		]
	};

	if (option && typeof option === 'object') {
		myChart.setOption(option);
	}
}

function fillChartFour(info) {

	let tmpDict = info[0];
	//  有效知识产权
	var dom = document.getElementById("dsj_zscqjg");
	var myChart = echarts.init(dom);

	var option = {
		color: colorsArr,
		tooltip: {
			trigger: 'item',
			formatter: '{b},{c},{d}%'

		},
		legend: {
			left: 'center',
			data: ['授权', '公布', '实用新型', '外观设计', '软件著作权']
		},
		series: [{
			name: '有效知识产权结构',
			type: 'pie',
			radius: ['36%', '60%'],
			avoidLabelOverlap: false,
			itemStyle: {
				borderRadius: 3,
				borderColor: '#FFFFFF',
				borderWidth: 3
			},
			label: {
				show: false,
				position: 'center'
			},
			labelLine: {
				show: true
			},
			data: [{
					value: tmpDict.fmsqYx,
					name: '授权'
				},
				{
					value: tmpDict.fmgbZs,
					name: '公布'
				},

				{
					value: tmpDict.syxxYx,
					name: '实用新型'
				},
				{
					value: tmpDict.wgsjYx,
					name: '外观设计'
				},
				{
					value: tmpDict.rzYx,
					name: '软件著作权'
				}
			],
			emphasis: {
				label: {
					show: true,
					fontSize: '20',
					fontWeight: 'bold'
				}
			}
		}]
	};

	if (option && typeof option === 'object') {
		myChart.setOption(option);
	}


}

function fillChartFive(info) {

	let tmpDict = info[0];

	//  获取多少个部门数组
	let deptArr = [];
	for (let s of info) {

		if (deptArr.indexOf(s.ipcDept) < 0) {
			deptArr.push(s.ipcDept)
		}
	}

	// 获取部门子类及值
	let subDeptArr = [];
	var startMyCount = 0;
	for (let s of deptArr) {

		let tmpArr = [];

		for (let t of info) {
			// 部门一样
			if (s == t.ipcDept) {

				if (t.ipcClass == tmpDict.ipcZbClass) {

					tmpArr.push({
						name: t.ipcClass,
						children: [{
							name: t.ipcNum,
							itemStyle: {
								// 
								color: 'orange',

							},
						}],
						itemStyle: {
							// 
							color: 'orange',
						},
					})
				} else {

					tmpArr.push({
						name: t.ipcClass,
						children: [{
							name: t.ipcNum,

						}]
					})
				}

			}
		}
		startMyCount++;

		subDeptArr.push(tmpArr);
	}

	console.log('deptarr长度 = ' + deptArr.length);

	let html = '';
	for (var i = 0; i < deptArr.length; i++) {

		let idStr = 'dsj_zlipc' + i;
		let myHeight = subDeptArr[i].length * 40 + 'px';
		html += `<div  id=${idStr} style="width: calc(100vw - 20px); height: ${myHeight};"></div>`
	}
	document.getElementById("dsj_zlipc_content").innerHTML = html;


	for (var i = 0; i < deptArr.length; i++) {

		let idStr = 'dsj_zlipc' + i;
		//  IpC结构
		var dom = document.getElementById(idStr);
		var myChart = echarts.init(dom);
		var data = {
			name: deptArr[i],
			children: subDeptArr[i],
			itemStyle: {
				// 
				color: '#A5D9FF',
			},
		};
		var option = {
			silent: true, //取消点击高亮
			tooltip: {
				trigger: 'item',
				triggerOn: 'mousemove'
			},
			series: [{
				type: 'tree',
				id: 0,
				name: '',
				data: [data],
				top: '12%',
				left: '10%',
				bottom: '10%',
				right: '10%',
				symbol: 'square',
				symbolSize: [42, 20],
				expandAndCollapse: true,
				edgeShape: 'polyline',
				edgeForkPosition: '63%',
				initialTreeDepth: 2,
				lineStyle: {
					width: 1
				},
				itemStyle: {
					// 
					color: '#A5D9FF',
				},
				label: {
					position: 'top',
					rotate: 0,
					verticalAlign: 'middle',
					horizontalAlign: 'middle',
					align: 'center',
					fontSize: 10,

				},
				leaves: {
					label: {
						position: 'top',
						rotate: 0,
						verticalAlign: 'middle',
						align: 'center'
					}

				},
				emphasis: {
					focus: 'descendant'
				},
				expandAndCollapse: true,
				animationDuration: 350,
				animationDurationUpdate: 350
			}]
		};
		if (option && typeof option === 'object') {
			myChart.setOption(option);
		}
	}


}
function fillChartSix(info) {

	let tmpDict = info[0];

	let SCOPEArr = []; // 年份
	let FMGB_ZSArr = []; //
	let FMSQ_YXArr = []; //授权
	let SYXX_YXArr = []; //实用新型
	let WGSJ_YXArr = []; // 外观设计有效数


	for (let s of info) {

		FMGB_ZSArr.push(s.fmgbZs)
		FMSQ_YXArr.push(s.fmsqYx)
		SYXX_YXArr.push(s.syxxYx)
		WGSJ_YXArr.push(s.wgsjYx)

		SCOPEArr.push(s.scope);

	}

	var dom = document.getElementById("dsj_zljz");
	var myChart = echarts.init(dom);
	var option;

	option = {
		color: ['#7021FF', '#C3A5FF', '#3181FF', '#A5D9FF'],
		silent: false, //取消点击高亮
		tooltip: {
			trigger: 'axis',
			axisPointer: {
				// Use axis to trigger tooltip
				type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
			}
		},
		legend: {
			data: ['类型一', '类型二', '类型三', '类型四']
		},
		grid: {
			left: '1%',
			right: '1%',
			bottom: '2%',
			containLabel: true
		},
		xAxis: {
			type: 'category',
			data: SCOPEArr,
			axisLabel: {

				fontSize: 7
			},

		},
		yAxis: {
			type: 'value',


		},
		series: [

			{
				name: '类型一',
				type: 'bar',
				barMaxWidth: 30,
				stack: 'total',
				label: {
					show: false
				},
				emphasis: {
					focus: 'series'
				},
				data: FMSQ_YXArr,

			},
			{
				name: '类型二',
				type: 'bar',
				barMaxWidth: 30,
				stack: 'total',
				label: {
					show: false
				},
				emphasis: {
					focus: 'series'
				},
				data: FMGB_ZSArr
			},
			{
				name: '类型三',
				type: 'bar',
				barMaxWidth: 30,
				stack: 'total',
				label: {
					show: false
				},
				emphasis: {
					focus: 'series'
				},
				data: SYXX_YXArr
			},
			{
				name: '类型四',
				type: 'bar',
				barMaxWidth: 30,
				stack: 'total',
				label: {
					show: false
				},
				emphasis: {
					focus: 'series'
				},
				data: WGSJ_YXArr
			},
		]
	};
	if (option && typeof option === 'object') {
		myChart.setOption(option);
	}

}
function fillChartSeven(info) {

	let tmpDict = info[0];
	//  法律
	var dom = document.getElementById("dsj_zlfl");
	var myChart = echarts.init(dom);
	var option = {
		color: ['#7021FF', '#AAB7C5', '#5AD8A6'],
		tooltip: {
			trigger: 'item',
			formatter: '{b},{c},{d}%'

		},
		legend: {
			top: '0%',
			left: 'center',
			data: ['有效', '无效', '在审']
		},
		series: [{
			name: '有效知识产权',
			type: 'pie',
			radius: ['36%', '60%'],
			avoidLabelOverlap: false,
			itemStyle: {
				borderRadius: 3,
				borderColor: '#FFFFFF',
				borderWidth: 3
			},
			label: {
				show: false,
				position: 'center'
			},
			labelLine: {
				show: true
			},
			data: [{
					value: tmpDict.efficient,
					name: '有效'
				},
				{
					value: tmpDict.invalid,
					name: '无效'
				},

				{
					value: tmpDict.underTrial,
					name: '在审'
				}
			],
			emphasis: {
				label: {
					show: true,
					fontSize: '20',
					fontWeight: 'bold'
				}
			},
		}]
	};

	if (option && typeof option === 'object') {
		myChart.setOption(option);
	}




}
function fillChartEight(info) {
	let tmpDict = info[0];
	let yearArr = []; // 年份
	let QUANTITYArr = []; //数量

	for (let s of info) {

		QUANTITYArr.push(s.quantity)
		yearArr.push(s.scope);

	}

	var dom = document.getElementById("dsj_zlsm");
	var myChart = echarts.init(dom);
	var option;

	option = {
		color: ['#7021FF'],
		silent: false, //取消点击高亮
		tooltip: {
			trigger: 'axis',
			axisPointer: {
				type: 'shadow'
			}
		},
		legend: {
			data: ['数量']
		},
		grid: {
			left: '2%',
			right: '2%',
			bottom: '2%',
			containLabel: true
		},
		xAxis: {
			type: 'category',
			data: yearArr,
			axisLabel: {

				fontSize: 10
			},
		},
		yAxis: {
			type: 'value'

		},
		series: [{
				name: '数量',
				type: 'bar',
				barMaxWidth: 30,
				stack: 'total',
				label: {
					show: false
				},
				data: QUANTITYArr
			}

		]
	};
	if (option && typeof option === 'object') {
		myChart.setOption(option);
	}


}
function fillChartNine(info, comNameStr) {

	let infoArr = info.unionList
	var tmpDict = infoArr[0];

	let dataArr = [];
	for (let s of infoArr) {

		if (s.unionName == tmpDict.unionCompany) {

			dataArr.push({
				name: s.unionName,
				value: s.unionNum,
				children: [{
					name: s.unionNum,
					itemStyle: {
						// 
						color: 'orange',
					},
				}],
				itemStyle: {
					// 
					color: 'orange',
				},
			})
		} else {

			dataArr.push({
				name: s.unionName,
				value: s.unionNum,
				children: [{
					name: s.unionNum
				}]
			})
		}

	}
	//  联合申请情况
	var dom = document.getElementById("dsj_zllhsq");
	dom.style.height = dataArr.length * 40 + 'px';
	if (dataArr.length > 12) {
		dom.style.marginTop = -(dataArr.length * 3.6) + 'px';

	}
	var myChart = echarts.init(dom);
	var data = {
		name: comNameStr,
		children: dataArr,
		itemStyle: {
			// 
			color: '#A5D9FF',
		},
	};
	var option = {
		tooltip: {
			trigger: 'item',
			triggerOn: 'mousemove'
		},
		silent: true, //取消点击高亮
		series: [{
			type: 'tree',
			id: 0,
			name: 'tree1',
			data: [data],
			top: '12%',
			left: '10%',
			bottom: '10%',
			right: '10%',
			symbol: 'square',
			symbolSize: [42, 20],
			expandAndCollapse: true,
			edgeShape: 'polyline',
			edgeForkPosition: '60%',
			initialTreeDepth: 2,
			lineStyle: {
				width: 1
			},
			itemStyle: {
				// 
				color: '#A5D9FF',
			},
			label: {
				position: 'top',
				rotate: 0,
				verticalAlign: 'middle',
				align: 'middle',
				fontSize: 9
			},
			leaves: {
				label: {
					position: 'top',
					rotate: 0,
					verticalAlign: 'middle',
					align: 'center'
				}
			},
			emphasis: {
				focus: 'descendant'
			},
			expandAndCollapse: true,
			animationDuration: 350,
			animationDurationUpdate: 350
		}]
	};
	if (option && typeof option === 'object') {
		myChart.setOption(option);
	}


}




module.exports = {



	fillChartOneTwo,
	fillChartThree,
	fillChartFour,
	fillChartFive,
	fillChartSix,
	fillChartSeven,
	fillChartEight,
	fillChartNine,





}